home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 13066 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.5 KB

  1. Path: mail2news.demon.co.uk!txwang
  2. From: Wang TianXing <gztxwang@public1.guangzhou.gd.cn>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Dynamically initializing static members
  5. Date: Sat, 23 Mar 1996 18:37:08 GMT
  6. Message-ID: <199603230651.OAA15366@public1.guangzhou.gd.cn>
  7. X-NNTP-Posting-Host: txwang
  8. X-Newsreader: Forte Free Agent 1.0.82
  9. X-Mail2News-Path: public1.guangzhou.gd.cn!txwang
  10.  
  11. On 22 Mar 1996 10:11:18 GMT, apardon@rc1.vub.ac.be (Antoon Pardon)
  12. wrote:
  13.  
  14. | I am playing with the idea of somekind of classregistration.
  15.  
  16. | The registration class would provide for a function: 
  17.  
  18. | unsigned int Registrate(const char *name);
  19.  
  20. | This would keep the name of the function stored somewhere and
  21. | would return a registration ID.
  22.  
  23. | The idea would be to include a static int into the class that
  24. | would store this ID something like this
  25.  
  26. | class MYCLASS {
  27. |   static unsigned int
  28. |     Registration_ID
  29.  
  30. |   ...
  31.  
  32. | }
  33.  
  34. | The problem now is how do I assign this Registration_ID
  35. | automatically. In Modula 2 you have initialisation code
  36. | that is called at the start of the program where you might
  37. | then put code similar to 
  38.  
  39. | MYCLASS::Registration_D = Registrate("MYCLASS");
  40.  
  41. | Is something similar possible in C++ or do I have to
  42. | do it in a different way? I looked at the FAQ but
  43. | couldn't find an answer there.
  44.  
  45. If you write the line as
  46.  
  47. unsigned int MYCLASS::Registration_ID = Registrate("MYCLASS");
  48.  
  49. it should work.  If it really doesn't work, buy a better compiler.
  50.  
  51. ---
  52. Wang TianXing
  53.  
  54.  
  55.